import axios from "axios";
//创建axios对象
const request = axios.create({
    //后端地址
    baseURL: '/thsap',
    //超时时间
    timeout: 180000,
    //请求头
    headers: {
        "Content-Type": "application/json;charset=utf-8",
        // 'Access-Control-Allow-Origin': '*',
        'Accept': 'application/json'
    }
})

//拦截请求
request.interceptors.request.use(config => {
    return config
})
//返回的结果
request.interceptors.response.use(response => {
    const type = response.request.responseType || ''
    // 下载类型特殊处理文件名
    if (type.includes('blob')) {
      const disposition = response.headers['content-disposition']
      let filename = '' // 下载错误用假文件代替
      if (disposition && disposition.indexOf('filename=') !== -1) {
        filename = decodeURI(disposition.substring(disposition.indexOf('filename=') + 9, disposition.length))
      }
      response.data.filename = filename
    }
    return response.data
    },
    error => {
        return Promise.reject(error)
    })
export default request
